/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ConEmpleadosView.java
 *
 * Created on 22/02/2012, 09:24:26 PM
 */
package view;

import entity.Empleado;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import service.EurekaService;

/**
 *
 * @author Administrador
 */
public class ConEmpleadosView extends javax.swing.JInternalFrame {

	private static ConEmpleadosView instancia = null;
	
	static {
		instancia = new ConEmpleadosView();
	}

	public static ConEmpleadosView getInstancia() {
		return instancia;
	}
	
	/** Creates new form ConEmpleadosView */
	private ConEmpleadosView() {
		initComponents();
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
   // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
   private void initComponents() {

      jLabel1 = new javax.swing.JLabel();
      txtPaterno = new javax.swing.JTextField();
      btnConsultar = new javax.swing.JButton();
      jScrollPane1 = new javax.swing.JScrollPane();
      tblDatos = new javax.swing.JTable();
      btnCerrar = new javax.swing.JButton();

      setClosable(true);
      setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
      setTitle("CONSULTAR EMPLEADOS");

      jLabel1.setText("Paterno");

      btnConsultar.setText("Consultar");
      btnConsultar.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            btnConsultarActionPerformed(evt);
         }
      });

      tblDatos.setModel(new javax.swing.table.DefaultTableModel(
         new Object [][] {
            {null, null, null, null, null},
            {null, null, null, null, null},
            {null, null, null, null, null},
            {null, null, null, null, null}
         },
         new String [] {
            "ID", "PATERNO", "MATERNO", "NOMBRE", "USUARIO"
         }
      ) {
         Class[] types = new Class [] {
            java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
         };
         boolean[] canEdit = new boolean [] {
            false, false, false, false, false
         };

         public Class getColumnClass(int columnIndex) {
            return types [columnIndex];
         }

         public boolean isCellEditable(int rowIndex, int columnIndex) {
            return canEdit [columnIndex];
         }
      });
      jScrollPane1.setViewportView(tblDatos);
      tblDatos.getColumnModel().getColumn(0).setResizable(false);
      tblDatos.getColumnModel().getColumn(1).setResizable(false);
      tblDatos.getColumnModel().getColumn(2).setResizable(false);
      tblDatos.getColumnModel().getColumn(3).setResizable(false);
      tblDatos.getColumnModel().getColumn(4).setResizable(false);

      btnCerrar.setText("Cerrar");
      btnCerrar.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            btnCerrarActionPerformed(evt);
         }
      });

      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
         layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
               .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 543, Short.MAX_VALUE)
               .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addComponent(jLabel1)
                     .addComponent(txtPaterno, javax.swing.GroupLayout.PREFERRED_SIZE, 293, javax.swing.GroupLayout.PREFERRED_SIZE))
                  .addGap(18, 18, 18)
                  .addComponent(btnConsultar, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addGap(18, 18, 18)
                  .addComponent(btnCerrar, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addContainerGap())
      );
      layout.setVerticalGroup(
         layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addGroup(layout.createSequentialGroup()
                  .addComponent(jLabel1)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE)
                  .addComponent(txtPaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
               .addComponent(btnConsultar, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
               .addComponent(btnCerrar, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
      );

      pack();
   }// </editor-fold>//GEN-END:initComponents

	private void btnCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCerrarActionPerformed
		this.setVisible(false);
	}//GEN-LAST:event_btnCerrarActionPerformed

	private void btnConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConsultarActionPerformed
		// Limpiando la tabla
		DefaultTableModel model = (DefaultTableModel) tblDatos.getModel();
		model.setNumRows(0);
		// Dato
		String paterno = txtPaterno.getText();
		// Proceso
		try {
			EurekaService srv = new EurekaService();
			List<Empleado> lista = srv.conEmpleados(paterno);
			for (Empleado emp : lista) {
				model.addRow(emp.toArray());
			}
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage(), 
					  "ERROR", JOptionPane.ERROR_MESSAGE);
		}
	}//GEN-LAST:event_btnConsultarActionPerformed

   // Variables declaration - do not modify//GEN-BEGIN:variables
   private javax.swing.JButton btnCerrar;
   private javax.swing.JButton btnConsultar;
   private javax.swing.JLabel jLabel1;
   private javax.swing.JScrollPane jScrollPane1;
   private javax.swing.JTable tblDatos;
   private javax.swing.JTextField txtPaterno;
   // End of variables declaration//GEN-END:variables
}
